/** 
 * 标示集合 
 */
var globalVar = null;
var marking = {
    path: "http://yhq.lenovo.com.cn",
    CookieShareId: "",
    wxJs: null,
    userIdentify: {
        path: '',
        attenStatus: "", //0未关注1已关注
        clubCardTatus: "", //会员领取状态 0--未领取  1---已领取
        inputStatus: "", //是否录入信息0未录入1已录入
        redDrawStatus: '', //红包获取红包中奖状态:0未中奖1已中奖
        redReceiveStatus: '', //获取红包领取状态:0未领取1已领取
        redAmount: "", //红包金额
        remainPlayNumber: '', //可玩次数
        source: "",
        shareId: ""
    }
};
/**
 * 微信授权
 */
if (!isWeiXin()) {//非微信测试
    window.location.href = 'http://yhq.lenovo.com.cn/v1/lenovo/landingPage.do';
} else {
    var deviceId = operateCookie.getCookie("fenli_deviceID");
    var CookieShareId = operateCookie.getCookie("fenli_shareID");
    marking.CookieShareId = CookieShareId;
    var source = unescape(getParameter("source"));
    marking.userIdentify.source = source;
    marking.userIdentify.shareId = unescape(getParameter("shareId"));

    //判断是否存在cookie，如果不存在则去授权
    if (deviceId == null || deviceId == "" || source == "" || marking.userIdentify.shareId == "") {
        if (source == "") {
            window.location.href = marking.userIdentify.path + "/v1/lenovo/card/lucky2018.do";
        } else {
            if (marking.userIdentify.shareId == "") {
                
                window.location.href = marking.userIdentify.path + "/v1/lenovo/card/lucky2018.do?source=" + source;
            } else {
                
                window.location.href = marking.userIdentify.path + "/v1/lenovo/card/lucky2018.do?source=" + source + "&shareId=" + marking.userIdentify.shareId;
            }
        }
    } else {
        
        //获取用户标示
        $.ajax({
            url: marking.userIdentify.path + "/v1/lenovo/lucky2018/validateUser.do",
            type: "post",
            dataType: "jsonp",
            data: {
                shareId: marking.userIdentify.shareId
            },
            success: function (data) {
                
                if (data.result == "ok") {
                    //向当前数据集中添加数据
                    for (var i in marking.userIdentify) {
                        if (data.values[i] != "undefined" || data.values[i] != "") {
                            marking.userIdentify[i] = data.values[i];
                        }
                    }
                    //获取用户表示成功后调用浏览记录接口
                    marking.userIdentify.path = "http://yhq.lenovo.com.cn"; //全局固定链接前缀
                    var source = unescape(getParameter("source"));
                    marking.userIdentify.source = source;
                    marking.userIdentify.shareId = unescape(getParameter("shareId"));

                    trackUrl();
                    saveShareAccessRecord();
                    $("body .loading").hide();
                    //数据本地存储
                    if(localStorage.getItem("user")){
                        localStorage.removeItem('user');
                    }
                    localStorage.setItem('user', JSON.stringify(marking.userIdentify));
                    //读取，更新
                    globalVar = JSON.parse(localStorage.getItem("user"));
                } else {
                    //无用户，重新授权
                    if (data.values == "userNull") {
                        window.location.href = marking.userIdentify.path + "/v1/lenovo/card/lucky2018.do";
                    }
                }
            },
            error: function (data) {
            }
        });

    }
}